#!/bin/bash

event_log_file=/home/typecast/results/logs/event_log.txt
id=1

ts=`date +"%F %T"`   
echo "$ts: starting event logger" > $event_log_file
echo "$ts: place $id stop" >> $event_log_file
echo "$ts: starting event logger, you should be stopping at place $id"

while true; do 
   while true; do 
	leaveNow=0; 
	ts=`date +"%F %T"`;   
   	echo -n "$ts: enter when you are ready to leave place $id";    	
   	tick=0; 
   	while (( $tick < 30 )) ; do 
   		echo -n "."
   		read -t 2 command; 
   		if (( $? == 0 )); then 
   			leaveNow=1;
   			break; 
   		fi;    
   		let tick=$tick+1; 		
    done
    if (( $leaveNow == 0 )) ; then
    	echo; 
    	continue; 
    else
    	ts=`date +"%F %T"`;   
    	echo "$ts: place $id leave" >> $event_log_file;
    	echo "$ts: leave from place $id"; 
    	break;
    fi
   done


   let id=$id+1; 

   while true; do 
	stopNow=0; 
	ts=`date +"%F %T"`;   
   	echo -n "$ts: enter when you are ready to stop at place $id";    	
   	tick=0; 
   	while (( $tick < 30 )) ; do 
   		echo -n "."
   		read -t 2 command; 
   		if (( $? == 0 )); then 
   			stopNow=1;
   			break; 
   		fi; 
   		let tick=$tick+1; 		   		
    done
    if (( $stopNow == 0 )) ; then
    	echo; 
    	continue; 
    else
    	ts=`date +"%F %T"`;   
    	echo "$ts: place $id stop" >> $event_log_file;
    	echo "$ts: stop at place $id"; 
    	break;
    fi
   done;
done
	
    	   		















	
tick=0;
while [[ $tick -lt 50 ]] ; do 
  sleep 1; 
  echo -n "."; 
  let i=$tick/10;
  if [[ $i -eq 10 ]]; then 
       echo ;
  fi
  let tick=$tick+1; 
done  
echo
ts=`date +%F-%T`
echo -n "$ts sending data in 10 seconds " 
tick=0; 
while [[ $tick -lt 10 ]]; do
  sleep 1; 
  echo -n ".";
  let tick=$tick+1; 
done

echo

ts=`date +%F-%T`
echo "$ts sending data now, duration will be 4 minutes" 
echo "$ts sending data now, duration will be 4 minutes" >> $event_log_file
 
